﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;
using ListItem=Coolite.Ext.Web.ListItem;
using System.Collections.Generic;
using Button=Coolite.Ext.Web.Button;

public partial class User_UserAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CXSecurity.ChkDept("1");
        CXSecurity.ChkBoss(Cookies.getCookies("cuid"));
    }
    [AjaxMethod]
    public void AddUser(object sender, AjaxEventArgs e)
    {
        if (TfUsername.Text == "")
        {
            Ext.Msg.Show(new MessageBox.Config
            {
                Buttons = MessageBox.Button.CANCEL,
                Title = "错误",
                Message = "用户名不能为空！",
                Icon = MessageBox.Icon.INFO
            });
        }
        else
        {
            Query q = new Query(CxUserBase.Schema);
            q.AddWhere("username", TfUsername.Text);
            if (q.GetRecordCount() > 0)
            {
                Ext.Msg.Show(new MessageBox.Config
                                 {
                                     Buttons = MessageBox.Button.CANCEL,
                                     Title = "错误",
                                     Message = "数据库中已存在该用户，请更换用户名。",
                                     Icon = MessageBox.Icon.INFO
                                 });
            }
            else
            {
                if (TfPassWD1.Text != TfPassWD2.Text)
                {
                    Ext.MessageBox.Show(new MessageBox.Config
                                            {
                                                Buttons = MessageBox.Button.CANCEL,
                                                Title = "错误",
                                                Message = "两次输入密码不一致！",
                                                Icon = MessageBox.Icon.ERROR
                                            });
                }
                else
                {
                    CxUserBase cx = new CxUserBase();
                    cx.Username = TfUsername.Text;
                    cx.PassWD = TfPassWD1.Text;
                    cx.Depid = int.Parse(ComboBox1.SelectedItem.Value);
                    
                    if(Checkbox7.Checked)
                    {
                        cx.LevelID = 1;
                    }
                    else
                    {
                        cx.LevelID = 0;
                    }
                    int t = 0;
                     
                    cx.SecurityNum = t;
                    cx.Status = 1;
                    cx.Save();
                    Ext.Msg.Show(new MessageBox.Config
                                     {
                                         Buttons = MessageBox.Button.OK,
                                         Title = "添加用户",
                                         Message = "成功！",
                                         Icon = MessageBox.Icon.INFO
                                     });

                }
            }
        }
    }
}
